package com.example.scaffold_demo.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.httplibrary.mvp.BaseView;
import com.example.httplibrary.mvp.proxy.FragmentMvpProxy;
import com.example.httplibrary.mvp.proxy.FragmentMvpProxyImpl;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;


/**
 * Author: 李巷阳
 * Date: 2020/6/22
 * Part:
 * Description:
 */
public abstract class BaseFragment extends Fragment implements BaseView {

    private FragmentMvpProxy mMvpProxy;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getLayout(), null);
        return view;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // 创建 Mvp 的代理
        mMvpProxy = createMvpProxy();
        initView();
        initData();
    }

    protected FragmentMvpProxy createMvpProxy() {
        if(mMvpProxy == null){
            mMvpProxy = new FragmentMvpProxyImpl(this) {
            };
        }
        // 创建preserter,并把activity生命周期绑定至presenter
        mMvpProxy.bindAndCreatePresenter(this);
        return mMvpProxy;
    };

    protected abstract void initData();

    protected abstract void initView();


    protected abstract int getLayout() ;

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}
